package com.chinanet.netelementmodel;

import com.chinanet.entry.netelement.Attr;
import com.chinanet.entry.netelement.AttrType;
import com.chinanet.entry.netelement.WorkInterFace;
import com.chinanet.utils.webservice.AttrsIn;
import com.chinanet.utils.webservice.WebService;

import java.util.HashMap;
import java.util.Map;

/**
 * HP_WebService_Imp_findAccountInfo
 * 宽带帐号信息查询
 * @author xuzhi
 *
 */
public class HP_WebService_Imp_findAccountInfo implements WorkInterFace {

	@Override
	public String getName() {
		return "hp宽带帐号信息查询";
	}

	@Override
	public String getDesciption() {
		return "";
	}

	@Override
	public int getVersion() {
		return 0;
	}

	@Override
	public Attr[] getInAttrs() {
		Attr[] in=new Attr[1];
		in[0]=new Attr("Login", "值表示登录名全称：如hzhza12345678;对于普通宽带用户,不需要带后缀@zj(默认为@zj),但是对于卡用户,必须带后缀@tyt", AttrType.TYPE_String, true);
		return in;
	}

	@Override
	public Attr[] getOutAttrs() {
		Attr[] out = new Attr[25];
		out[0]=new Attr("ReturnCode", "0：成功；其它：失败", AttrType.TYPE_Int, true);
		out[1]=new Attr("Result", "返回结果的根节点", AttrType.TYPE_String, true);
		out[2]=new Attr("error", "值表示错误信息, 比如请求报文数据格式不对", AttrType.TYPE_String, true);
		out[3]=new Attr("userinfo", "表示查询用户的返回信息", AttrType.TYPE_String, true);
		out[4]=new Attr("login", "表示完整的用户登录名", AttrType.TYPE_String, true);
		out[5]=new Attr("user_node", "表示用户所在地市节点", AttrType.TYPE_String, true);
		out[6]=new Attr("status", "表示用户当前的状态", AttrType.TYPE_String, true);
		out[7]=new Attr("status_reason", "用户锁类型", AttrType.TYPE_String, true);
		out[8]=new Attr("last_mod_time", "用户信息最后修改时间", AttrType.TYPE_String, true);	
		out[9]=new Attr("plan_name", "产品描述", AttrType.TYPE_String, true);
		out[10]=new Attr("channels", "上网信道", AttrType.TYPE_String, true);
		out[11]=new Attr("fixed_line_permit", "固网接入权限", AttrType.TYPE_String, true);
		out[12]=new Attr("fixed_line_maxsession", "固网接入最大会话数", AttrType.TYPE_String, true);
		out[13]=new Attr("wlan_permit", "WLAN接入权限,0 禁止wlan漫游;1:c4节点wlan漫游;2:c3节点wlan漫游;3:省内漫游;4:跨省漫游;5 热点绑定", AttrType.TYPE_String, true);
		out[14]=new Attr("wlan_maxsession", "WLAN接入最大会话数", AttrType.TYPE_String, true);
		out[15]=new Attr("wlan_international_wlan_roam", "WLAN国际漫游权限;0 开启:1 关闭", AttrType.TYPE_String, true);
		out[16]=new Attr("phs_permit", "小灵通接入权限;-1表示禁止小灵通接入;0表示主叫绑定不限制;1表示主叫绑定限制", AttrType.TYPE_String, true);
		out[17]=new Attr("phs_maxsession", "小灵通接入最大会话数", AttrType.TYPE_String, true);
		out[18]=new Attr("xvc_info", "表示具体的一组XVC绑定信息, 可以有多组", AttrType.TYPE_String, true);
		out[19]=new Attr("nas_domain", "表示NAS归属域", AttrType.TYPE_String, true);
		out[20]=new Attr("xvc_xpi", "XVC-XPI,int [0,4096)", AttrType.TYPE_String, true);
		out[21]=new Attr("xvc_xci", "", AttrType.TYPE_String, true);
		out[22]=new Attr("log", "服务器返回的soapxml", AttrType.TYPE_String, true);
		out[23]=new Attr("Errormsg", "服务器返回的错误信息,当ReturnCode为0的时候就不必去读取", AttrType.TYPE_String, false);
		out[24]=new Attr("bspeed", "产品带宽大小：单位（M）", AttrType.TYPE_Int, true);
		return out;
	}

	@Override
	public Map<String, Object> init(Map<String, Object> data) {
		AttrsIn attrsIn=new AttrsIn();
		WebService webService=new WebService();
		Map<String,Object> map=new HashMap<String, Object>();
		//Get into arguments
		attrsIn.setClientSysName("CDMA");
		attrsIn.setFunctionName("gethpmess");
		attrsIn.setRequestMessage("<DN>"+(String) data.get("Login")+"</DN>");
		//Get soapxml
		String returnXml=webService.WebServiceInit(attrsIn);
		String flag=webService.getPattern("flag", returnXml);
		if(flag.equals("true")){
			map.put("ReturnCode", 0);
			map.put("Result", webService.getPattern("Result", returnXml));
			map.put("error", webService.getPattern("error", returnXml));
			System.out.println(webService.getPattern("error", returnXml));
			map.put("userinfo", webService.getPattern("userinfo", returnXml));
			map.put("login", webService.getPattern("login", returnXml));
			String usernode="无地区";
			int usernodeflag=Integer.parseInt(webService.getPattern("user_node", returnXml));
			if(usernodeflag==57601){
				usernode="台州";
			}else if(usernodeflag==57602){
				usernode="临海";
			}else if(usernodeflag==57603){
				usernode="三门";
			}else if(usernodeflag==57604){
				usernode="黄岩";
			}else if(usernodeflag==57605){
				usernode="温岭";
			}else if(usernodeflag==57606){
				usernode="玉环";
			}else if(usernodeflag==57607){
				usernode="仙居";
			}else if(usernodeflag==57608){
				usernode="天台";
			}else if(usernodeflag==57609){
				usernode="椒江";
			}else if(usernodeflag==57610){
				usernode="路桥";
			}
			map.put("user_node", usernode);

			String status="无状态";
			int statusflag=Integer.parseInt(webService.getPattern("status", returnXml));
			if(statusflag==0){
				status="废弃";
			}else if(statusflag==10100){
				status="正常";
			}else if(statusflag==10102){
				status="锁定";
			}else if(statusflag==10103){
				status="已销户";
			}
			map.put("status", status);

			String status_reason="其它";
			int status_reasonflag=Integer.parseInt(webService.getPattern("status_reason", returnXml));
			if(status_reasonflag==0){
				status_reason="未锁定";
			}else if(status_reasonflag==2){
				status_reason="客户未启用";
			}else if(status_reasonflag==4){
				status_reason="欠费锁定";
			}else if(status_reasonflag==8){
				status_reason="客户主动锁";
			}else if(status_reasonflag==16){
				status_reason="锁定待销户";
			}else if(status_reasonflag==128){
				status_reason="其它";
			}
			map.put("status_reason", status_reason);

			map.put("last_mod_time", webService.getPattern("last_mod_time", returnXml));
			map.put("plan_name", webService.getPattern("plan_name", returnXml));
			map.put("channels", webService.getPattern("channels", returnXml));

			String fixed_line_permit="未知";
			int fixed_lineflag=Integer.parseInt( webService.getPattern("permit",webService.getPattern("fixed_line", returnXml)));
			if(fixed_lineflag==0){
				fixed_line_permit="不许可";
			}else if(fixed_lineflag==1){
				fixed_line_permit="许可";
			}

			map.put("fixed_line_permit",fixed_line_permit);

			map.put("fixed_line_maxsession", webService.getPattern("maxsession",webService.getPattern("fixed_line", returnXml)));
			map.put("wlan_permit", webService.getPattern("permit",webService.getPattern("wlan", returnXml)));
			map.put("wlan_maxsession", webService.getPattern("maxsession",webService.getPattern("wlan", returnXml)));
			map.put("wlan_international_wlan_roam",webService.getPattern("international_wlan_roam",webService.getPattern("wlan", returnXml)));
			map.put("phs_permit", webService.getPattern("permit",webService.getPattern("phs", returnXml)));
			map.put("phs_maxsession", webService.getPattern("maxsession",webService.getPattern("phs", returnXml)));
			map.put("xvc_info", webService.getPattern("xvc_info", returnXml));
			map.put("nas_domain", webService.getPattern("nas_domain", returnXml));
			map.put("xvc_xpi", webService.getPattern("xvc_xpi", returnXml));
			map.put("xvc_xci", webService.getPattern("xvc_xci", returnXml));


			String a[]=webService.getPattern("plan_name", returnXml).split("\\，");
			String bspeed="详情中无宽带速率";
			for(String b:a){
				if(b.indexOf("M")!=-1){
					bspeed=b.replaceAll("M","");
				}
			}
			map.put("bspeed", bspeed);
			
			map.put("log", webService.dealkouhao(returnXml));
			map.put("Errormsg", "");
			map.put("flag",1);
		}else{
			map.put("flag",0);
			map.put("ReturnCode", 1);
			map.put("Result", "");
			map.put("error", "");
			map.put("userinfo", "");
			map.put("login", "");
			map.put("user_node","");
			map.put("status", "");
			map.put("status_reason", "");
			map.put("last_mod_time", "");
			map.put("plan_name", "");
			map.put("channels","");
			map.put("fixed_line_permit","" );
			map.put("fixed_line_maxsession", "");
			map.put("wlan_permit", "");
			map.put("wlan_maxsession","" );
			map.put("wlan_international_wlan_roam","");
			map.put("phs_permit","");
			map.put("phs_maxsession", "");
			map.put("xvc_info", "");
			map.put("nas_domain","" );
			map.put("xvc_xpi", "");
			map.put("xvc_xci", "");
			map.put("log", webService.dealkouhao(returnXml));
			map.put("Errormsg", "网元侧执行出错，处理请求失败");
		}
		
		return map;
	}

}
